package jas.bank;

import jas.rpc.RemoteException;
import jas.rpc.RemoteObject;
import jas.rpc.client.RemoteStub;
import jas.rpc.client.RpcClient;

/**
 * Client-side implementation of an Account. All methods result in RPC calls.
 */
public class Account_Stub implements Account, RemoteStub {
    
    private RemoteObject obj;
    private RpcClient client;
    
    public Account_Stub(RemoteObject obj, RpcClient client) {
        this.obj = obj;
        this.client = client;
    }

    public String getName() throws RemoteException {
        return client.remoteCall(String.class, obj.getId(), "getName", new Object[0], new Class[0]);
    }

    public double getBalance() throws RemoteException {
        return client.remoteCall(Double.class, obj.getId(), "getBalance", new Object[0], new Class[0]);
    }

    public void deposit(Double amount) throws RemoteException {
       client.remoteCall(null, obj.getId(), "deposit", new Object[] {amount}, new Class[]{Double.class});
    }

    public void withdraw(Double amount) throws RemoteException {
       client.remoteCall(null, obj.getId(), "withdraw", new Object[] {amount}, new Class[]{Double.class});
    }

    public RemoteObject getRemoteObject() {
        return obj;
    }
    
}
